package com.ifcar.app.activity.newspage;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.ifcar.app.activity.AccountLogin;
import com.ifcar.app.activity.BaseActivity;
import com.ifcar.app.activity.CollectActivity;
import com.ifcar.app.activity.CommonFrameActivity;
import com.ifcar.app.activity.ImageSwitcherActivity;
import com.ifcar.app.activity.LinkOutSide;
import com.ifcar.app.activity.MyCommentsActivity;
import com.ifcar.app.activity.NewsPage;
import com.ifcar.app.activity.ShareToMicroBlog;
import com.ifcar.app.activity.ShowBigPic;
import com.ifcar.app.activity.VideoPlayActivity;
import com.ifcar.app.activity.common.CommentFragment;
import com.ifcar.app.bean.DetailPageBean;
import com.ifcar.app.db.DBUtils;
import com.ifcar.app.db.NewsSQLiteOpenHelper;
import com.ifcar.app.fragment.NRFragment;
import com.ifcar.app.model.Videos;
import com.ifcar.app.rss.GetColumnsInfo;
import com.ifcar.app.rss.GetComments;
import com.ifcar.app.util.CollectUtil;
import com.ifcar.app.util.Constant;
import com.ifcar.app.util.FileUtils;
import com.ifcar.app.util.HttpUtils;
import com.ifcar.app.util.NewsPageHelper;
import com.ifcar.app.util.PicUtil;
import com.ifcar.app.util.StringUtil;
import com.ifcar.app.util.ThemeSettingsHelper;
import com.ifcar.app.util.Tools;
import com.ifcar.app.activity.R;
import com.netease.util.Pair;
import com.netease.util.ReflectUtils;
import com.netease.util.SystemUtils;

public class NewsFragment extends NRFragment{
    public static final String SHOW_GO_COMMENT = "show_go_news";
    
	private ImageView mGuideView;
	private View mReplyFrame;
	private View mTopBanner;
	private View mNewsContentView;
	private ViewFlipper mViewFlipper;
	private View mLoaddingView;
	private View mLoaddingErrorView;
	private View mTurnToLeft;
	private View mTurnToRight;
	private WebView mWebView1;
	private WebView mWebView2;
	private Button mCommentBtn;
	private View reply_img_layout;
	private View reply_img_button;
	private View reply_edittext_layout;
	private Button replyButton;
	private EditText replyEditText;
	private View replyLayout;
	private ImageView share_button;
	private CheckBox collectBtn;
	
	private Animation slideLeftIn;
	private Animation slideLeftOut;
	private Animation slideRightIn;
	private Animation slideRightOut;
	private Animation slideTopIn;
	private Animation slideTopOut;
	private Animation slideBottomIn;
	private Animation slideBottomOut;
	
	private Context mContext;
	private SharedPreferences mSPreferences; 
	private int mLastestFontSize;
	private int mCurrentFontSize;
//	private String mPreHtmlPath = "";
	private String mHtmlPath = "";
	private boolean screenctrl, leftrightctrl, isSliding, isFromOlympicVideo;
	private String videoStrig;
	
	private Map<String, Object> map = new HashMap<String, Object>();
	private Map<String, Object> moreMap = new HashMap<String, Object>();
	private Map<String, Object> fullMap = new HashMap<String, Object>();
//	private List<String> docIDList = new ArrayList<String>();
//	private List<HashMap<String, Object>> specailIDList = new ArrayList<HashMap<String, Object>>();
	private List<String> idList;
	private String docid = "", columnid = "", columnname = "", collectTitle = "", title = "", url = "", replyCountNum = "0";
	private boolean isHeadline, is_topic, mIsLocalNews, iscomeMyReply, isCollect;
	private int startNum, sdkversion;
	private List<ResolveInfo> sharelist;
	private String quote = "";
	private boolean replyWithQuote;
	private final int isDetailPageReply = 1;
	private CollectUtil cu;
	private int autoId;
	
	private final String DETAIL_GUIDE_TAG = "detailpageguide";
	public static final  String TAILTYPE = "tail", HEADTYPE = "head", ID_JSON_STRING = "id_json_string";
	
	private InputMethodManager mInputMethodManager;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setNRMenu(R.layout.news_page_menu, new int[] {
                R.id.menu_refresh, R.id.menu_selecttext, R.id.menu_textsize,
                R.id.menu_my_comment, R.id.menu_my_collect });
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContext = getActivity();
		return inflater.inflate(R.layout.news_page_pageguide, null);
	}
	
	@Override
	public void onViewCreatedNR(View view, Bundle savedInstanceState) {
		super.onViewCreatedNR(view, savedInstanceState);
		mGuideView = (ImageView) ((ViewStub) view.findViewById(R.id.viewstub_detailguide)).inflate().findViewById(R.id.news_guide);
		mReplyFrame = view.findViewById(R.id.detail_page_reply_frame);
		reply_img_layout = view.findViewById(R.id.reply_img_layout);
		reply_img_button = mReplyFrame.findViewById(R.id.reply_img_button);
		reply_edittext_layout = mReplyFrame.findViewById(R.id.reply_edittext_layout);
		replyButton = (Button) mReplyFrame.findViewById(R.id.reply_button);
		replyEditText = (EditText) mReplyFrame.findViewById(R.id.reply_edittext);
		
		mNewsContentView = view.findViewById(R.id.detail_page_content_layout);
		mViewFlipper = (ViewFlipper)view.findViewById(R.id.webview_flipper);
		mWebView1 = (WebView)view.findViewById(R.id.detail_page_webview1);
		mWebView2 = (WebView)view.findViewById(R.id.detail_page_webview2);
		mLoaddingView = view.findViewById(R.id.original_loadingbar);
		mLoaddingView.setVisibility(View.VISIBLE);
		mLoaddingErrorView = view.findViewById(R.id.original_netease_bg);
		
		mTurnToLeft = view.findViewById(R.id.slide_to_left);
		mTurnToRight = view.findViewById(R.id.slide_to_right);
		
		replyLayout = view.findViewById(R.id.detail_page_reply_frame);
		share_button = (ImageView) replyLayout.findViewById(R.id.share_button);
		collectBtn = (CheckBox) replyLayout.findViewById(R.id.collect_button);
		
		slideLeftIn = AnimationUtils.loadAnimation(mContext, R.anim.slide_left_in);
		slideLeftOut = AnimationUtils.loadAnimation(mContext, R.anim.slide_left_out);
		slideRightIn = AnimationUtils.loadAnimation(mContext, R.anim.slide_right_in);
		slideRightOut = AnimationUtils.loadAnimation(mContext, R.anim.slide_right_out);

		slideTopIn = AnimationUtils.loadAnimation(mContext, R.anim.slide_top_in);
		slideTopOut = AnimationUtils.loadAnimation(mContext, R.anim.slide_top_out);
		slideBottomIn = AnimationUtils.loadAnimation(mContext, R.anim.slide_bottom_in);
		slideBottomOut = AnimationUtils.loadAnimation(mContext, R.anim.slide_bottom_out);
		
        View titleView = getTitleView();
        mTopBanner = titleView;
        if (titleView != null) {
            boolean showGoComment = getArguments() != null && getArguments().getBoolean(SHOW_GO_COMMENT, true);

            ViewGroup extraLayout = (ViewGroup)titleView.findViewById(R.id.top_right_extra_container);
            LayoutInflater inflater = LayoutInflater.from(getActivity());
            View topButtonView = inflater.inflate(R.layout.top_button_layout, extraLayout, false);
            extraLayout.addView(topButtonView);
            if (showGoComment) {
                extraLayout.setVisibility(View.VISIBLE);
            } else {
                extraLayout.setVisibility(View.GONE);
            }

            mCommentBtn = (Button)topButtonView.findViewById(R.id.top_button); 
            mCommentBtn.setText("跟贴");
            mCommentBtn.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (replyCountNum != null && replyCountNum.equals("0")) {
                        Toast.makeText(getActivity(), "目前没有跟贴", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    
                    // TODO 暂时使用这种方法解决
                    if ("跟贴".equals(mCommentBtn.getText())) {
                        return;
                    }
                    
                    if (getParent() != null && getParent() instanceof NewsCommentFragment &&  map != null) {
                        JSONObject j = new JSONObject();
                        String replyBoard = "";
                        try {
                            j.put(GetComments.P_TAG, "");
                            j.put(GetColumnsInfo.POSTID_TAG, docid);
                            Object o = null;
                            if (null != map) {
                                o = map.get(GetColumnsInfo.REPLYBOARD_TAG);
                            }
                            replyBoard = o == null ? "" : o.toString();
                            j.put("replyBoard", replyBoard);

                            String title = map.get(GetColumnsInfo.TITLE_TAG) == null ? "" : map
                                    .get(GetColumnsInfo.TITLE_TAG).toString();

                            Bundle bundle = new Bundle();
                            bundle.putString(CommentFragment.BOARD_ID, replyBoard);
                            bundle.putString(CommentFragment.DOC_ID, docid);
                            bundle.putString(CommentFragment.DOC_TITLE, title);
                            bundle.putBoolean(Videos.IS_FROM_VIDEO, isFromOlympicVideo);
                            bundle.putString(CommentFragment.COMMENT_URL, j.toString());
                            ((NewsCommentFragment) getParent()).showComment(bundle);
                        } catch (Exception e) {
                            e.printStackTrace();
                            return;
                        }
                    }
                }
            });
            
            View goBackView = titleView.findViewById(R.id.go_back_common_btn);
            goBackView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (getParent() != null) {
                        ((NewsCommentFragment) getParent()).goback();
                    }
                }
            });
        }
        
        mTopBanner.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				((WebView)((FrameLayout)mViewFlipper.getCurrentView()).getChildAt(0)).scrollTo(0, 0);
			}
		});
	}
	
	
	
	@Override
    public void onTabSelected(boolean first) {
        super.onTabSelected(first);
        if (first) {
            Bundle args = getArguments();
            if (args != null && "push".equals(args.getString("push"))) {
                NotificationManager nm = (NotificationManager) getActivity().getSystemService(
                        Context.NOTIFICATION_SERVICE);
                nm.cancel(R.drawable.stat_download_icon);
            }
            
            init();
            
            screenctrl = mSPreferences.getBoolean("screenctrl", false);
            leftrightctrl = mSPreferences.getBoolean("leftrightctrl", true);
            setCollectAttibute();
    		
    		loadedFileData();
        }
    }
	
	/**
	 * 加载文章数据
	 */
	private void loadedFileData() {
		
		Bundle bundle = getArguments();
		if(null != bundle){
			isFromOlympicVideo = bundle.getBoolean(Videos.IS_FROM_VIDEO);
			if(isFromOlympicVideo){ // 视频数据
				docid = bundle.getString(GetColumnsInfo.DOCID_TAG);
				videoStrig = bundle.getString(docid);
				columnid = "olympic_video";
				columnname = "视频";
				mReplyFrame.findViewById(R.id.reply_frame_divider_img2).setVisibility(View.GONE);
				mReplyFrame.findViewById(R.id.collect_button).setVisibility(View.GONE);
			} else { // 其他数据
				docid = bundle.getString(GetColumnsInfo.DOCID_TAG);
				columnid = bundle.getString(GetColumnsInfo.TID_TAG);
				columnname = bundle.getString(GetColumnsInfo.TNAME_TAG);
				if (null == columnname || "".equalsIgnoreCase(columnname)) {
					columnname = "新闻";
				}

				String positionStr = bundle.getString("position");
				if (TextUtils.isEmpty(positionStr)) {
				    startNum = 0;
				} else {
				    try {
				        startNum = Integer.valueOf(positionStr);
                    } catch (Exception e) {
                        startNum = 0;
                    }
				}

				String idjson = bundle.getString(ID_JSON_STRING);
				
				if(!TextUtils.isEmpty(idjson)){
					parseJson(idjson);
				}
				
				url = bundle.getString(GetColumnsInfo.URL_TAG);
				String replyCount = bundle.getString(GetColumnsInfo.REPLYCOUNT_TAG);
				if (replyCount != null && replyCount.contains("跟贴")) {
					replyCountNum = replyCount.substring(0, replyCount.length() - 2);
				} else if (replyCount != null) {
					replyCountNum = replyCount;
				}
				
				title = bundle.getString(GetColumnsInfo.TITLE_TAG);
				collectTitle = title;

				iscomeMyReply = bundle.getBoolean("iscomeMyReply", false);
				mIsLocalNews = bundle.getBoolean(GetColumnsInfo.TLOCAL_NEWS_TAG, false);
				isHeadline = bundle.getBoolean((String)GetColumnsInfo.HEADLINE_TAG);
				is_topic = bundle.getBoolean(StringUtil.IS_TOPIC);
				isCollect = bundle.getBoolean("isCollect", false);
			}
			
			loaddingData();
			
		} else { // 没有数据
			Toast.makeText(mContext, R.string.msg_loading_failed, Toast.LENGTH_SHORT).show();
		}
		
	      if (is_topic) {
	            setTitle(R.string.main_title_topic_depth);
	        } else {
	            setTitle(columnname);
	        }
	}
	
	private void parseJson(final String jsonString){
		try {
			JSONArray array = new JSONArray(jsonString);
			if(null != array && array.length() > 0){
				idList = new ArrayList<String>();
				for(int i = 0; i < array.length(); i ++){
					String id = array.getString(i);
					if(!TextUtils.isEmpty(id)){
						idList.add(id);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void loaddingData(){
		if(isFromOlympicVideo){
			initVideoData();
		} else {
//			docid = "822J909400011SM9";// 策划新闻
//			docid = "826AJI5000014JB5";// 大图新闻
//			docid = "7MEKH69N00964J9O";// 带视频的大图新闻
//			docid = "82AL00SA00051CA1";// 图集新闻
			map = FileUtils.readDetailPageData(docid);
			if (null == map) {
				if (!Tools.CheckNetwork(mContext)) {
					mHandler.sendEmptyMessage(404);
				} else {
					getNetDataByNewThread();
				}
			} else {
				mHandler.sendEmptyMessage(100);
				setIsReaded4List(docid);
			}
		}
	}
	
	private void initVideoData() {
		DetailPageBean bean = new DetailPageBean();
		bean.setData(GetColumnsInfo.getArticleMap(videoStrig, docid));
		url = (String) bean.getData().get(Videos.VURL_TAG);
		
		Bundle b = new Bundle();
		b.putSerializable("contents", bean);
		Message msg = new Message();
		msg.setData(b);
		msg.what = 5;
		msg.obj = docid;
		mHandler.sendMessage(msg);
	}
	
	private void init(){
		sdkversion = Integer.parseInt(VERSION.SDK);
		
		if (getThemeSettingsHelper().isNightTheme(mContext)) {
			mHtmlPath = "file:///android_asset/night_newspage.html";
//			mPreHtmlPath = "file:///android_asset/night_blank.html";
		} else {
			mHtmlPath = "file:///android_asset/newspage.html";
//			mPreHtmlPath = "file:///android_asset/blank.html";
		}
		
		mSPreferences = ((BaseActivity)getActivity()).sp;
		
		Bundle bundle = getArguments();
		boolean fromVideo = bundle.getBoolean(Videos.IS_FROM_VIDEO);
		if(!fromVideo){
			boolean isGuide = mSPreferences.getBoolean(DETAIL_GUIDE_TAG, true);
			if (isGuide) {
				try {
					mGuideView.setBackgroundResource(R.drawable.detailpageguideinfo);
					mGuideView.setOnClickListener(guideClickListener);
				} catch (java.lang.OutOfMemoryError e1) {
					mSPreferences.edit().putBoolean(DETAIL_GUIDE_TAG, false).commit();
					if (null != mGuideView) {
						mGuideView.setVisibility(View.GONE);
					}
				}
			}
		}
		mCurrentFontSize = mSPreferences.getInt("currentSizeId", 2);
		mLastestFontSize = mCurrentFontSize;
		
		setWebView(mWebView1);
		setWebView(mWebView2);
		
		setListeners();
		setTextSizeDialog();

		sharelist = Tools.getShareTargets(mContext, "message/rfc822");
		
		mInputMethodManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
	}
	
	@Override
    public boolean onMenuOpen() {
        return super.onMenuOpen();
    }

    @Override
    public void onMenuClick(int id) {
        switch (id) {
            case R.id.menu_refresh: 
            	refreshDoc();
                break;
            case R.id.menu_selecttext: 
            	emulateShiftHeld((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0));
                break;
            case R.id.menu_textsize: 
            	showTextSizeDialog();
                break;
            case R.id.menu_my_comment: 
            	startActivity(new Intent(mContext, MyCommentsActivity.class));
                break;
            case R.id.menu_my_collect: 
            	startActivity(new Intent(mContext, CollectActivity.class));
                break;
        }
    }
    
    private void refreshDoc(){
    	if(isFromOlympicVideo) {
    		initVideoData();
    	} else {
	    	mLoaddingErrorView.setVisibility(View.GONE);
			showProgress();
			(((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0)).setVisibility(View.GONE);
			mLoaddingView.setVisibility(View.VISIBLE);
			
			getNetDataByNewThread();
    	}
    }
    
    private void getNetDataByNewThread(){
    	new Thread() {
			public void run() {
				DetailPageBean bean = new DetailPageBean();
				bean.setData(GetColumnsInfo.getArticleContents(docid, HEADTYPE, mContext));
				Bundle b = new Bundle();
				b.putSerializable("contents", bean);
				Message msg = new Message();
				msg.setData(b);
				msg.what = 5;
				msg.obj = docid;
				mHandler.sendMessage(msg);
			}
		}.start();
    }
    
    private void emulateShiftHeld(WebView view) {
    	try {
    		if (sdkversion > 13) {
    		    boolean selected=false;
    			int x = (Integer) ReflectUtils.invokeMethod(view, "viewToContentX", new Object[] { 
						view.getScrollX() + view.getWidth() / 2 }, new Class[] { int.class });
    			int y = (Integer) ReflectUtils.invokeMethod(view, "viewToContentY", new Object[] { view.getScrollY()
    					+ view.getHeight() / 2 }, new Class[] { int.class });
    			selected=(Boolean) ReflectUtils.invokeMethod(view, "selectText", new Object[] { x, y }, new Class[] { int.class, int.class });
				if(!selected)
				   ReflectUtils.invokeMethod(view, "selectAll");
    		} else {
				view.emulateShiftHeld();
    		}
    	} catch (Exception e) {
		}
	}
    
    private void showTextSizeDialog(){
    	dialogInterface = textSizeDialog.setSingleChoiceItems(
    			new String[] { "超大", "大", "中", "小" }, mCurrentFontSize,
    			new DialogInterface.OnClickListener() {

    				@Override
					public void onClick(DialogInterface dialog, int which) {
						switch (which) {
						case 0:
							((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0)).loadUrl("javascript:showSuperBigSize()");
							break;
						case 1:
							((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0)).loadUrl("javascript:showBigSize()");
							break;
						case 2:
							((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0)).loadUrl("javascript:showMidSize()");
							break;
						case 3:
							((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0)).loadUrl("javascript:showSmallSize()");
							break;
						}

						mCurrentFontSize = which;

						if (mCurrentFontSize != mLastestFontSize) {
							mLastestFontSize = mCurrentFontSize;
							setTextSize((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0), mCurrentFontSize);
							mSPreferences.edit().putInt("currentSizeId", mCurrentFontSize).commit();
						}

						if (null != dialogInterface)
							dialogInterface.cancel();
					}

    			}).show();
    }
	
	private Builder textSizeDialog;
	private DialogInterface dialogInterface;
	private void setTextSizeDialog() {
		textSizeDialog = new AlertDialog.Builder(mContext).setTitle("文字大小");
		textSizeDialog.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(DialogInterface arg0, int arg1, KeyEvent arg2) {
				// TODO Auto-generated method stub
				if (arg1 == KeyEvent.KEYCODE_BACK) {
					arg0.cancel();
					if (mCurrentFontSize != mLastestFontSize) {
						mCurrentFontSize = mLastestFontSize;
						setTextSize((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0), mCurrentFontSize);
					}
					return true;
				}

				if (arg1 == KeyEvent.KEYCODE_SEARCH) {
					if (mCurrentFontSize != mLastestFontSize) {
						mCurrentFontSize = mLastestFontSize;
						setTextSize((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0), mCurrentFontSize);
					}
					return false;
				}
				return false;
			}

		});
	}
	
	private void setAnimations(){
		slideTopOut.setAnimationListener(mAnimationListener);
		slideBottomOut.setAnimationListener(mAnimationListener);
		slideTopIn.setAnimationListener(mAnimationListener);
		slideBottomIn.setAnimationListener(mAnimationListener);
	}
	
	private int sharetype = -1;
	private void setListeners() {
		enableReply(false);

		setAnimations();
		
		replyButton.setOnClickListener(replyClickListener);
		mTurnToLeft.setOnClickListener(pageTurnListener);
		mTurnToRight.setOnClickListener(pageTurnListener);
		
		reply_img_button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				replyEditText.requestFocus();
				
				if (mInputMethodManager != null) {
					mInputMethodManager.showSoftInput(replyEditText, 0);
				}
				reply_img_layout.setVisibility(View.GONE);
				reply_edittext_layout.setVisibility(View.VISIBLE);
				mTopBanner.startAnimation(slideTopOut);
			}
		});
		
		mLoaddingErrorView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				refreshDoc();
			}
		});
		
		// 收藏
		collectBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				cu = new CollectUtil(mContext);
				if (autoId != -1) {
					cu.deleteAlreadyCollect(autoId, CollectUtil.COLLECT_ARTICLE);
					collectBtn.setChecked(false);
					Toast.makeText(mContext, getString(R.string.cancel_collect), Toast.LENGTH_SHORT).show();
				} else {
					if (TextUtils.isEmpty(collectTitle)) {
						collectTitle = (String) map.get(GetColumnsInfo.TITLE_TAG);
					}
					Long flag = cu.doCollectObject(url, collectTitle, docid, CollectUtil.COLLECT_ARTICLE);

					if (flag == -1) {
						collectBtn.setChecked(false);
						Toast.makeText(mContext, getString(R.string.fail_collect), Toast.LENGTH_SHORT).show();
					} else {
						collectBtn.setChecked(true);
						Toast.makeText(mContext, getString(R.string.success_collect),Toast.LENGTH_SHORT).show();
					}
				}
				autoId = cu.getAlreadyCollect(url, docid, CollectUtil.COLLECT_ARTICLE);
			}
		});
		
		share_button.setOnClickListener(new View.OnClickListener() {// 文章分享
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(mContext)
				.setTitle("分享")
				.setItems(new String[] {getString(R.string.share_to_weibo),
						getString(R.string.share_to_sina),
						getString(R.string.share_to_qq),
						getString(R.string.share_to_renren),
						getString(R.string.share_to_ydnote),
						getString(R.string.share_to_sms),
						getString(R.string.share_to_email),
						getString(R.string.share_to_other), },
						new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						
						String sharetitle = null == map ? "" : (String) map .get(GetColumnsInfo.TITLE_TAG);
						String shareurl = url;
						Object obj = null == map ? null : map.get(GetColumnsInfo.IMG_TAG);
						String shareimg = "";
						StringBuilder imgSrc = null;
						String imgName = "";
						if (null != obj) {
							List<Map<String, Object>> list = (List<Map<String, Object>>) obj;
							if (null != list && list.size() > 0) {
								shareimg = "" + ((Map<String, Object>) list.get(0)).get(GetColumnsInfo.SRC_TAG);
								imgSrc = new StringBuilder(shareimg);
								imgSrc.insert("http://".length(),"s.cimg.163.com/i/");
								imgSrc.append(".220x220.auto.jpg");
								imgName = imgSrc.substring(imgSrc.lastIndexOf("/") + 1, imgSrc.length());
							}
						}
						sharetype = -1;
						Intent shareintent = new Intent();
						shareintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
						shareintent.setClass(mContext, ShareToMicroBlog.class);
						Bundle bundle = new Bundle();
						bundle.putString("sharetitle", sharetitle);
						bundle.putString("shareurl", shareurl);
						bundle.putString("shareimg", shareimg);

						switch (arg1) {
						// 网易微博
						case Constant.SHARE_NETEASE:
							bundle.putInt("sharetype", 0);
							shareintent.putExtras(bundle);
							startActivity(shareintent);
							break;
						// 新浪微博
						case Constant.SHARE_SINA:
							bundle.putInt("sharetype", 1);
							bundle.putString("imgname", imgName);
							shareintent.putExtras(bundle);
							startActivity(shareintent);
							break;
						// 腾讯微博
						case Constant.SHARE_QQ:
							bundle.putInt("sharetype", 2);
							bundle.putString("imgname", imgName);
							shareintent.putExtras(bundle);
							startActivity(shareintent);
							break;
						case Constant.SHARE_RENREN:
							bundle.putInt("sharetype", 3);
							bundle.putString("imgname", imgName);
							shareintent.putExtras(bundle);
							startActivity(shareintent);
							break;
						// 有道笔记
						case Constant.SHARE_YDNOTE:
							sharetype = 4;
							bundle.putInt("sharetype", 4);
							bundle.putString("imgname", imgName);

							bundle.putString("sharetitle", getShareHtml(map, shareurl, 4));
							bundle.putString("sharetitleyd", sharetitle);

							shareintent.putExtras(bundle);
							startActivity(shareintent);
							break;
						case Constant.SHARE_SMS:
							new AsyncTask<String, Integer, Map<String, Object>>() {
								
								@Override
								protected Map<String, Object> doInBackground(String... params) {
									String shorturl = HttpUtils.getDocShortUrl("wap", params[0], mContext);
									String wwwshorturl = HttpUtils.getDocShortUrl("www", params[0], mContext);
									Map<String, Object> map = new HashMap<String, Object>();
									map.put("wap", shorturl);
									map.put("www", wwwshorturl);
									return map;
								}

								@Override
								protected void onPostExecute(Map<String, Object> result) {
									super.onPostExecute(result);

									String shorturl = (String) result.get("wap");
									String wwwshorturl = (String) result.get("www");

									Intent sendIntent = new Intent(Intent.ACTION_VIEW);
									sendIntent.putExtra("sms_body", getString(R.string.share_sms_text)
											+ "《" + map.get(GetColumnsInfo.TITLE_TAG) + "》"
											+ getString(R.string.share_with_u) + ":"
											+ getString(R.string.share_url_wap) + " "
											+ shorturl + " " + getString(R.string.share_url_www)
											+ " " + wwwshorturl);
									sendIntent.setType("vnd.android-dir/mms-sms");
									startActivity(sendIntent);

								}

							}.execute(url);
							break;
						case Constant.SHARE_EMAIL:
							if (null != sharelist && sharelist.size() > 0) {
								try {
									new AsyncTask<String, Integer, String>() {
										@Override
										protected String doInBackground( String... params) {
											return HttpUtils.getDocShortUrl( "www", params[0], mContext);
										}
										
										@Override
										protected void onPostExecute(String result) {
											super.onPostExecute(result);

											Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
											emailIntent.setType("message/rfc822");
											emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
													getString(R.string.share_email_title));

											String html = getShareHtml(map, result, -1);

											emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(html));
											startActivity(Intent.createChooser(emailIntent,
													getString(R.string.select_email_client)));
										}

									}.execute(url);

								} catch (Exception e) {
									e.printStackTrace();
									Toast.makeText(mContext, getString(R.string.share_email_failure),
											Toast.LENGTH_SHORT).show();
								}
							} else {
								Toast.makeText(mContext, getString(R.string.share_email_noclient),
										Toast.LENGTH_SHORT).show();
							}

							break;
						case Constant.SHARE_OTHER:
							new AsyncTask<String, Integer, Map<String, Object>>() {

								@Override
								protected Map<String, Object> doInBackground(String... params) {
									// TODO
									String shorturl = HttpUtils.getDocShortUrl("wap", params[0], mContext);
									String wwwshorturl = HttpUtils.getDocShortUrl("www", params[0], mContext);

									Map<String, Object> map = new HashMap<String, Object>();
									map.put("wap", shorturl);
									map.put("www", wwwshorturl);
									return map;
								}

								@Override
								protected void onPostExecute(Map<String, Object> result) {
									super.onPostExecute(result);

									String shorturl = (String) result.get("wap");
									String wwwshorturl = (String) result.get("www");

									Intent intent = new Intent(Intent.ACTION_SEND);
									intent.setType("text/plain");
									intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
									intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_sms_text)
											+ "《" + map.get(GetColumnsInfo.TITLE_TAG) + "》"
											+ getString(R.string.share_with_u)
											+ getString(R.string.share_url_wap)
											+ shorturl + getString(R.string.share_url_www)
											+ wwwshorturl);
									
									startActivity(Intent.createChooser(intent,((BaseActivity)getActivity()).getTitle()));
								}

							}.execute(url);
							break;
						}
					}
				}).setNegativeButton("取消", null).show();
			}
			
		});
		
	}
	
	// 分享文章获取正文
	private String getShareHtml(Map<String, Object> shareMap, String shorturl, int type) {
		StringBuilder html = new StringBuilder();
		
		html.append(getString(R.string.share_email_text))
				.append("<html><head></head><body style=\"margin:0px; padding:0px;\">")
				.append("<center><div style=\"color:#464646;font-size:18px;font-weight:bold;\" >")
				.append(shareMap.get(GetColumnsInfo.TITLE_TAG)).append("</div>")
				.append("<div style=\"color:#949494;font-size:12px\" >")
				.append(shareMap.get(GetColumnsInfo.PTIME_TAG)).append("</div>")
				.append("<div style=\"color:#949494;font-size:12px\" >").append("来源： ")
				.append(shareMap.get(GetColumnsInfo.SOURCE_TAG)).append("</div>")
				.append("</center><div style=\"color:#5c5c5c;font-size:16px;\" > ")
				.append("<p>").append(getString(R.string.share_email_text))
				.append("</p>").append("<p>原文地址：<a href=\"").append(shorturl)
				.append("\">").append(shorturl).append("</a></p>")
				.append(getBodyWithImg4Mail()).append("</div>");

		if (shareMap.get(GetColumnsInfo.HASNEXT_TAG) != null
				&& Boolean.parseBoolean(shareMap.get(GetColumnsInfo.HASNEXT_TAG) + "")) {
			html.append("<center><a href=\"").append(shorturl)
					.append("\">查看全文</a></center>") .append("<p>原文地址：<a href=\"").append(shorturl)
					.append("\">").append(shorturl).append("</a></p>");
			if (type == 4) {
				html.append("<--insert-->");
			}
			html.append("</body></html>");
		} else {
			html.append("<p>原文地址：<a href=\"").append(shorturl).append("\">")
					.append(shorturl).append("</a></p>");
			if (type == 4) {
				html.append("<--insert-->");
			}
			html.append("</body></html>");
		}

		return html.toString();
	}
	
	private String getBodyWithImg4Mail() {
		if (null != map && map.get(GetColumnsInfo.BODY_TAG) != null) {
			String body = map.get(GetColumnsInfo.BODY_TAG).toString();

			if (map.get(GetColumnsInfo.IMG_TAG) != null) {
				List<Map<String, Object>> imgList = (List<Map<String, Object>>) map.get(GetColumnsInfo.IMG_TAG);
				
				Map<String, Object> imgMap = new HashMap<String, Object>();
				String imgTag = "";
				StringBuilder imgSrc = null;

				for (int i = 0; i < imgList.size(); i++) {
					imgMap = imgList.get(i);
					imgTag = imgMap.get(GetColumnsInfo.REF_TAG).toString();
					imgSrc = new StringBuilder(imgMap.get(
							GetColumnsInfo.SRC_TAG).toString());

					int tagIndex = body.indexOf(imgTag);
					if (tagIndex != -1) {
						body = body.replace(body.substring(tagIndex,
								tagIndex + imgTag.length()), sharetype == 4 ? "<p><img src=\"" + imgSrc.toString()
								+ "\" /></p>" : "<p><a href=\"" + imgSrc.toString() + "\">" + imgSrc.toString() + "</a></p>");
					}
				}
			}
			return body;

		}
		return "";
	}
	
	private String account = "";
	// 发表跟贴
	private View.OnClickListener replyClickListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			account = mSPreferences.getString("account", "");
			if ("".equals(account)) {

				if (replyEditText.getText() != null
						&& !replyEditText.getText().toString().equals("")) {

					if (replyEditText.getText().toString().length() <= 1
							|| replyEditText.getText().toString().length() > 1000) {
						Toast.makeText(mContext, "回复请在2-1000字内", Toast.LENGTH_SHORT).show();
						return;
					}

					Intent Loginintent = new Intent(mContext, AccountLogin.class);
					Loginintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					Bundle bundle = new Bundle();

					bundle.putBoolean("isreply", true);
					bundle.putBoolean("replyWithQuote", replyWithQuote);

					bundle.putString("replydocid", docid);
					bundle.putString("replyquote", quote);
					bundle.putString("replyBoard",null == map ? "" : ""
							+ map.get(GetColumnsInfo.REPLYBOARD_TAG));
					bundle.putString("replycontent", replyEditText.getText().toString());
					Loginintent.putExtras(bundle);
					mContext.startActivity(Loginintent);

				} else {
					Toast.makeText(mContext, "不能发空消息", Toast.LENGTH_SHORT).show();
				}

			} else {
				if (replyEditText.getText() != null
						&& !replyEditText.getText().toString().equals("")) {

					if (replyEditText.getText().toString().length() <= 1
							|| replyEditText.getText().toString().length() > 1000) {
						Toast.makeText(mContext, "回复请在2-1000字内", Toast.LENGTH_SHORT).show();
						return;
					}
					final String board = (String)map.get(GetColumnsInfo.REPLYBOARD_TAG);
					final String did = docid;
					final String text = replyEditText.getText().toString();
					final String a = account;

					postCommentThread(board, did, text, a, false, "", isDetailPageReply);

				} else {
					Toast.makeText(mContext, "不能发空消息", Toast.LENGTH_SHORT).show();
				}

			}

		}
	};
	
	private ProgressDialog mPostCommentDialog;
	private void postCommentThread(final String board, final String docid, final String text, final String account,
			final boolean replyWithQuote, final String quote, final int type) {
		if(null == mPostCommentDialog){
			mPostCommentDialog = new ProgressDialog(mContext);
			mPostCommentDialog.setMessage(getString(R.string.post_comment));
			mPostCommentDialog.setCancelable(true);
		}
		mPostCommentDialog.show();
		new Thread() {
			public void run() {
				Message msg = new Message();
				msg.what = 15;
				msg.arg1 = type;
				if (replyWithQuote) {
					msg.obj = GetComments.postComment(board, docid, quote, text, account, "新闻客户端用户", "0.0.0.0", "false", mContext);
				} else {
					msg.obj = GetComments.postComment(board, docid, text, account, "新闻客户端用户", "0.0.0.0", "false", mContext);
				}
				mHandler.sendMessage(msg);
			}
		}.start();

	}
	
	private void enableReply(boolean isEnable) {
		reply_img_button.setEnabled(isEnable);
		share_button.setEnabled(isEnable);
		collectBtn.setEnabled(isEnable);
	}
	
	private void setCollectAttibute() {
		cu = new CollectUtil(mContext);
		autoId = cu.getAlreadyCollect(url, docid, CollectUtil.COLLECT_ARTICLE);
		setCollectStatus();
	}
	
	/**
	 * 在4.0的系统下判断当前是否是复制模式
	 * @return
	 */
	public boolean isSelectMode() {
		boolean isselectwebview1 = false;
		boolean isselectwebview2 = false;

		if (sdkversion > 10) { // 判断当前是否是3.0的系统及以上
			try {
				isselectwebview1 = (ReflectUtils.getValue(mWebView1, "mSelectCallback") == null ? false : true);
				isselectwebview2 = (ReflectUtils.getValue(mWebView2, "mSelectCallback") == null ? false : true);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} else {// 在3.0系统以下判断是否是复制模式
			try {
				isselectwebview1 = (Boolean) (ReflectUtils.getValue(mWebView1, "mSelectingText"));
				isselectwebview2 = (Boolean) ReflectUtils.getValue(mWebView2, "mSelectingText");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return isselectwebview1 || isselectwebview2;
	}
	
	private void setCollectStatus() {
		if (autoId != -1) {
			collectBtn.setChecked(true);
		} else {
			collectBtn.setChecked(false);
		}
	}
	
	private AnimationListener mAnimationListener = new Animation.AnimationListener() {
		@Override
		public void onAnimationStart(Animation animation) {}
		@Override
		public void onAnimationRepeat(Animation animation) {}
		@Override
		public void onAnimationEnd(Animation animation) {
			if(animation == slideTopOut) mTopBanner.setVisibility(View.GONE);
			else if(animation == slideBottomOut) replyLayout.setVisibility(View.GONE);
			else if(animation == slideTopIn) mTopBanner.setVisibility(View.VISIBLE);
			else if(animation == slideBottomIn) replyLayout.setVisibility(View.VISIBLE);
		}
	};
	
	private View.OnClickListener pageTurnListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			
			if(null == idList || idList.isEmpty()) return; 
			
			if (mLoaddingView.getVisibility() == View.VISIBLE
					|| ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(1).getVisibility() == View.VISIBLE) {
				return;
			}
			
			mViewFlipper.clearAnimation();
			if(v == mTurnToLeft) { // 向下
				++ startNum;
				if(startNum == idList.size()){
					-- startNum;
					Toast.makeText(mContext, "已经翻到最末尾", Toast.LENGTH_SHORT).show();
					return;
				}
				mViewFlipper.setInAnimation(slideLeftIn);
				mViewFlipper.setOutAnimation(slideLeftOut);
				mViewFlipper.showNext();
			} else if(v == mTurnToRight) { // 向上
				-- startNum;
				if(startNum < 0){
					++ startNum;
					Toast.makeText(mContext, "已经翻到最开头", Toast.LENGTH_SHORT).show();
					return;
				}
				mViewFlipper.setInAnimation(slideRightIn);
				mViewFlipper.setOutAnimation(slideRightOut);
				mViewFlipper.showNext();
			}
			
			FileUtils.clearCache(mContext);
			((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0).setVisibility(View.GONE);
			((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(1).setVisibility(View.VISIBLE);
			if(startNum >= idList.size() || startNum == -1) return;
			
			docid = idList.get(startNum);
			if (map != null) map.clear();
			
			if ((map = FileUtils.readDetailPageData(docid)) == null) {
				final String did = docid;
				new Thread() {
					public void run() {
						DetailPageBean bean = new DetailPageBean();
						bean.setData(GetColumnsInfo.getArticleContents(did, HEADTYPE, mContext));
						Bundle b = new Bundle();
						b.putSerializable("contents", bean);
						Message msg = new Message();
						msg.setData(b);
						msg.what = 1;
						msg.obj = did;
						mHandler.sendMessage(msg);
					}
				}.start();
			} else {
				showNewPage();
			}
		}
	};
	
	public void setCanPageTurn(){
		boolean isSelectText = isSelectMode();
		if(!leftrightctrl || isSelectText || null == idList || idList.size() <= 0){
			mTurnToLeft.setVisibility(View.GONE);
			mTurnToRight.setVisibility(View.GONE);
		}else{
			mTurnToLeft.setVisibility(View.VISIBLE);
			mTurnToRight.setVisibility(View.VISIBLE);
		}
	}
	
	private void setWebView(final WebView webView) {
		webView.clearCache(true);
		webView.setFocusable(false);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
		webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
		
		webView.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				super.onProgressChanged(view, newProgress);

				if (newProgress == 100) {
					if (mCurrentFontSize != 2){
						setTextSize((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0), mCurrentFontSize);
					}
					mLoaddingView.setVisibility(View.GONE);
					isSliding = false;
					((FrameLayout)mViewFlipper.getCurrentView()).getChildAt(1).setVisibility(View.GONE);
					((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0).setVisibility(View.VISIBLE);
				}
			}

		});
		
		webView.addJavascriptInterface(new JavaScriptInterface(), "news");
	}
	
	private void setIsReaded4List(String docid) {
        try {
            Message msg = Message.obtain();
            msg.what = 101;
            msg.obj = true;
            mHandler.sendMessage(msg);
            
            if(!TextUtils.isEmpty(docid)){//如果文章ID为空  则忽略
                
                String sql = "select * from "
                    + NewsSQLiteOpenHelper.ARTICLE_READ_LIST_TABLE + " where "
                    + NewsSQLiteOpenHelper.ARTICLE_READ_DOC_ID + "=?";
            
                SQLiteDatabase db = getDb();
                db.beginTransaction();
                try {
                    Cursor cursor = db.rawQuery(sql, new String[] { docid });
                    
                    if(null != cursor && cursor.getCount()==0){
                        DBUtils.insertDataToReadStatusTable(db, docid, columnid, "Y");
                    }
                    if(null != cursor){
                        cursor.close();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    db.setTransactionSuccessful();
                    db.endTransaction();
                }
            }
            
        } catch (Exception e) {
        }
    }
	
	// 新手引导
	private View.OnClickListener guideClickListener = new View.OnClickListener() {
		@Override
		public void onClick(View arg0) {
			mSPreferences.edit().putBoolean(DETAIL_GUIDE_TAG, false).commit();
			arg0.setVisibility(View.GONE);
		}
	};
	
	// 设置字体大小
	private void setTextSize(WebView webview, int id) {
		switch (id) {
		case 0:
			webview.loadUrl("javascript:showSuperBigSize()");
			break;
		case 1:
			webview.loadUrl("javascript:showBigSize()");
			break;
		case 2:
			webview.loadUrl("javascript:showMidSize()");
			break;
		case 3:
			webview.loadUrl("javascript:showSmallSize()");
			break;
		}
	}
	
	public class JavaScriptInterface {
		
		public String getTitle() {
			String title = "";
			if (null != map) {
				if (map.get(GetColumnsInfo.TITLE_TAG) != null) {
					title = map.get(GetColumnsInfo.TITLE_TAG).toString();
				} 
			}
			return title;
		}

		public String getBody(int htmlWidth) {
			return getNewsBody(htmlWidth ,false);
		}
		
		public String getMoreBody(int htmlWidth) {
			return getNewsBody(htmlWidth, true);
		}
		
		public void getMore() {
			
			final String did = docid;
			new Thread() {
				public void run() {
					DetailPageBean bean = new DetailPageBean();
					bean.setData(GetColumnsInfo.getArticleContents(did,
							TAILTYPE, mContext));
					Bundle b = new Bundle();
					b.putSerializable("contents", bean);
					Message msg = new Message();
					msg.setData(b);
					msg.what = 3;
					msg.obj = did;
					mHandler.sendMessage(msg);
				}
			}.start();
		}
		
		public int hasNext() {
			int hasNext = 0;
			if(isFromOlympicVideo){
				hasNext = 2;
			} else if (null != map) {
				if (map.get(GetColumnsInfo.HASNEXT_TAG) != null
						&& (Boolean)map.get(GetColumnsInfo.HASNEXT_TAG)) {
					hasNext = 1;
				} 
			}
			return hasNext;

		}

		public String getTime() {
			String ptime= "";
			if (null != map) {
				if (map.get(GetColumnsInfo.PTIME_TAG) != null){
					ptime = (String)map.get(GetColumnsInfo.PTIME_TAG);
				}
			}
			return ptime;
		}

		public String getSource() {
			String source = "";
			if (null != map) {
				Object o = map.get(GetColumnsInfo.SOURCE_TAG);
				source = null == o ? "" : (isFromOlympicVideo ? "" : "来源:") + o.toString();
				if (!isFromOlympicVideo && source.length() > 15)
					source = source.substring(0, 13) + "..";
			}
			return source;
		}

		public int getReplyCount() {
			int replayCount = -1;
			if (null != map) {
				if (map.get(GetColumnsInfo.REPLYCOUNT_TAG) != null)
					replayCount = Integer.parseInt((String)map.get(GetColumnsInfo.REPLYCOUNT_TAG));
			} 
			return replayCount;
		}

		public String getReplyBoard() {
			String replyBoard = "";
			if (null != map) {
				if (map.get(GetColumnsInfo.REPLYBOARD_TAG) != null)
					replyBoard = map.get(GetColumnsInfo.REPLYBOARD_TAG).toString();
			}
			return replyBoard;
		}

		public void showBigPic(int i) {
			getPic(i);
		}

		public void triggerFullScreen() {
			if (!isSliding && screenctrl){
				mHandler.sendEmptyMessage(8);
			}
			mHandler.sendEmptyMessage(16);
		}

		@SuppressWarnings("unchecked")
		public void toLink(final int i) {
			
			List<Map<String, Object>> linkList = new ArrayList<Map<String, Object>>();
			
			List<Map<String, Object>> linkList1 = (List<Map<String, Object>>) map.get(GetColumnsInfo.LINK_TAG);
			List<Map<String, Object>> linkList2 = (List<Map<String, Object>>) moreMap.get(GetColumnsInfo.LINK_TAG);
			if(null != linkList1){
				linkList.addAll(linkList1);
			}
			if(null != linkList2){
				linkList.addAll(linkList2);
			}
			
			if (null != linkList && linkList.size() > 0) {
				
				Map<String, Object> linkMap = linkList.get(i);
				String type = (String) linkMap.get(GetColumnsInfo.TYPE_TAG);

				if ("doc".equals(type)) {
					Intent intent = new Intent(mContext, NewsPage.class);
					String docid = (String) linkMap.get(GetColumnsInfo.ID_TAG);
					Bundle extras = new Bundle();
					extras.putString("docid", docid);
					intent.putExtras(extras);
					mContext.startActivity(intent);
				} else {
					Intent intent = new Intent(mContext, LinkOutSide.class);
					String href = (String) linkMap.get(GetColumnsInfo.HREF_TAG);
					Bundle extras = new Bundle();
					extras.putString("href", href);
					intent.putExtras(extras);
					mContext.startActivity(intent);
				}
			}

		}
		
	}
	
	@SuppressWarnings("unchecked")
	private String getNewsBody(int htmlWidth, boolean isMore) {
		final WebView webView = ((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0));
		boolean downpic = mSPreferences.getBoolean("downpic", false);
		boolean isDownloadPic = !Tools.isshowimg(downpic, mContext);
		
		Map<String, Object> dataMap = isMore ? moreMap : map;
		
		int pImgCount = 0;
		int pLinkCount = 0;
		if(isMore){
			if(null != map.get(GetColumnsInfo.IMG_TAG)){
				pImgCount = ((List<Map<String, Object>>)map.get(GetColumnsInfo.IMG_TAG)).size() ;
			}
			if(null != map.get(GetColumnsInfo.VIDEO_TAG)){
				pImgCount += ((List<Map<String, Object>>)map.get(GetColumnsInfo.VIDEO_TAG)).size();
			}
			if(null != map.get(GetColumnsInfo.LINK_TAG)){
				pLinkCount = ((List<Map<String, Object>>)map.get(GetColumnsInfo.LINK_TAG)).size(); 
			}
		} 
		if(isFromOlympicVideo){
			List<Map<String, Object>> covers = (List<Map<String, Object>>) dataMap.get(GetColumnsInfo.VIDEO_TAG);
			if(null != covers && covers.size() > 0){
				String imgSize = GetColumnsInfo.getVideoListImgSize(mContext);
				int len = covers.size();
				for(int i = 0; i < len; i ++){
					Map<String, Object> item = covers.get(i);
					String cover = (String) item.get(GetColumnsInfo.COVER_TAG);
					if(!TextUtils.isEmpty(cover)){
						cover = cover.replace(imgSize, htmlWidth + "x" + htmlWidth);
						item.put(GetColumnsInfo.COVER_TAG, cover);
					}
				}
			}
		}
		
		String body = NewsPageHelper.getBody(mContext, webView, dataMap,
				isMore, pImgCount, pLinkCount, isDownloadPic, Tools.getScreenMetrics(mContext), htmlWidth);
		
		return body;
	}

	@SuppressWarnings("unchecked")
	private void getPic(int i) {
		if (isSliding) return;
		
		List<Map<String, Object>> mediaList = new ArrayList<Map<String, Object>>();
		if(null != map && null != map.get(GetColumnsInfo.IMG_TAG)){
			mediaList.addAll((List<Map<String, Object>>)map.get(GetColumnsInfo.IMG_TAG));
		}
		if(null != map && null != map.get(GetColumnsInfo.VIDEO_TAG)){
			mediaList.addAll((List<Map<String, Object>>)map.get(GetColumnsInfo.VIDEO_TAG));
		} 
		if(null != moreMap && null != moreMap.get(GetColumnsInfo.IMG_TAG)) {
			mediaList.addAll((List<Map<String, Object>>)moreMap.get(GetColumnsInfo.IMG_TAG));
		}
		if(null != moreMap && null != moreMap.get(GetColumnsInfo.VIDEO_TAG)){
			mediaList.addAll((List<Map<String, Object>>)moreMap.get(GetColumnsInfo.VIDEO_TAG));
		} 
		
		int length = mediaList.size();
		if(i < length){
			
			Map<String, Object> mediaMap = mediaList.get(i);
			String mediaType = (String) mediaMap.get(GetColumnsInfo.MEDIA_TYPE);
			
			if(GetColumnsInfo.MEDIA_VIDEO.equals(mediaType)){ // 视频
				playVideoBySystem(mediaMap);
			} else { // 图片
				if(!SystemUtils.isSDCardMounted()){
					showImageOrImageSet(mediaMap);
				} else {
					String imgUrl = (String) mediaMap.get(GetColumnsInfo.SRC_TAG);
					Pair<String, String> p = NewsPageHelper.getImgDownloadUrl(imgUrl, Tools.getScreenMetrics(mContext));
					if(PicUtil.isLocalPicExit(p.second.replace("_small", ""))){
						showImageOrImageSet(mediaMap);
					}
				}
			}
			
		}
		
	}
	
	// 调用系统组件播放视频
	private void playVideoBySystem(final Map<String, Object> mediaMap) {}
	
	
	// 显示大图或者调整图集
	private void showImageOrImageSet(Map<String, Object> imgMap){
		StringBuilder imgSrc = new StringBuilder((String)imgMap.get(GetColumnsInfo.SRC_TAG));
		
		String imgSetObj = (String) imgMap.get(GetColumnsInfo.PHOTOSET_ID_TAG);
		
		if(!TextUtils.isEmpty(imgSetObj)){ // 图集
			
			Intent intent = new Intent(mContext, ImageSwitcherActivity.class);
            Bundle bundle = new Bundle();
            String channel = imgSetObj.substring(0, imgSetObj.indexOf("|"));
        	String setid = imgSetObj.substring(imgSetObj.indexOf("|") + 1);
            String clientcover = imgSrc.toString();
            
            bundle.putString("setid", setid);
            bundle.putString("channel", channel);
            bundle.putString("imgsum", "0");
            bundle.putString("imgTitle", title);
            bundle.putString("clientcover", clientcover);
            intent.putExtras(bundle);
            startActivity(intent);
		} else {
			imgSrc.insert("http://".length(), "s.cimg.163.com/i/");
			int screentype = Tools.getScreenMetrics(mContext);
			if (1 == screentype) {
				imgSrc.append(".180x300.auto_small.jpg");
			} else if (2 == screentype) {
				imgSrc.append(".220x370.auto_small.jpg");
			} else {
				imgSrc.append(".420x740.auto_small.jpg");
			}
			
			Bundle bundle = new Bundle();
			String orgImg = imgMap.get(GetColumnsInfo.SRC_TAG).toString();
			
			bundle.putString(GetColumnsInfo.ORG_IMAGE_TAG, orgImg);
			bundle.putString(GetColumnsInfo.DOWNLOAD_IMGSRC_TAG, imgSrc.toString());
			bundle.putString(GetColumnsInfo.ALT_TAG, imgMap.get(GetColumnsInfo.ALT_TAG).toString());
			
			Intent intent = new Intent(mContext, ShowBigPic.class);
			intent.putExtras(bundle);
			
			startActivity(intent);
		}
	}
	
	public static float getTextSize(int sizeId) {
		float rst = 18.0f;
		if (0 == sizeId) {
			rst = 26.0f;
		} else if (1 == sizeId) {
			rst = 22.0f;
		} else if (2 == sizeId) {
			rst = 16.0f;
		} else if (3 == sizeId) {
			rst = 14.0f;
		}

		return rst;
	}
	
	public static float getTextSize(Context context) {
	    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return getTextSize(sp.getInt("currentSizeId", 2));
    }
	
	Toast pageTurn;
	private void showNewPage() {
		try {
			mLoaddingErrorView.setVisibility(View.GONE);
			mLoaddingView.setVisibility(View.GONE);

			if (map.get(GetColumnsInfo.REPLYCOUNT_TAG) != null) {
				int c1 = 0;
				c1 = Integer.parseInt(map.get(GetColumnsInfo.REPLYCOUNT_TAG).toString());
				replyCountNum = c1 + "";
			}
			
			mCommentBtn.setText(replyCountNum + "跟贴");
			WebView w = ((WebView) ((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(0));
			w.setId(1);
			w.loadUrl(mHtmlPath);
			
			if(null == pageTurn){
				pageTurn = Toast.makeText(mContext, "第" + (startNum + 1) + "篇", Toast.LENGTH_SHORT);
			}
			pageTurn.cancel();
			pageTurn.setText("第" + (startNum + 1) + "篇");
			pageTurn.show();
			
			url = GetColumnsInfo.Article_Url + docid + "/" + HEADTYPE + ".html";
			collectTitle = "" + map.get(GetColumnsInfo.TITLE_TAG);
			setCollectAttibute();
			setIsReaded4List(docid);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
	}
	
	private Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);

			switch (msg.what) {
			case 0:
				getPic(msg.arg1);
				break;
			case 1:
				if (msg.obj == null || !msg.obj.toString().equals(docid)) {
					break;
				}

				if (map != null) map.clear();

				DetailPageBean bean = (DetailPageBean) msg.getData() .getSerializable("contents");

				if (bean != null && bean.getData() != null)
					map = bean.getData();

				if (!isCollect && (map == null || map.isEmpty())) {
					if (!Tools.CheckNetwork(mContext)) {
						Toast.makeText(mContext, R.string.msg_net_error, Toast.LENGTH_SHORT).show();
					} else {
						Toast.makeText(mContext, R.string.msg_get_news_error, Toast.LENGTH_SHORT).show();
					}
					
					((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(1).setVisibility(View.GONE);
					mLoaddingErrorView.setVisibility(View.VISIBLE);
					mCommentBtn.setText("跟贴");
				} else {
					mLoaddingErrorView.setVisibility(View.GONE);
					FileUtils.writeDetailPageData(map, docid);
					showNewPage();
				}
				isSliding = false;
				break;
			case 3: // use
				if (moreMap != null)
					moreMap.clear();

				DetailPageBean bean2 = (DetailPageBean) msg.getData().getSerializable("contents");

				if (bean2 != null && bean2.getData() != null)
					moreMap = bean2.getData();
				
				try {

					if (map != null && !map.isEmpty() && moreMap != null) {
						fullMap.clear();
						fullMap.put(GetColumnsInfo.TITLE_TAG, map
								.get(GetColumnsInfo.TITLE_TAG) == null ? ""
								: map.get(GetColumnsInfo.TITLE_TAG).toString());
						fullMap.put(
								GetColumnsInfo.REPLYCOUNT_TAG,
								map.get(GetColumnsInfo.REPLYCOUNT_TAG) == null ? ""
										: map.get(GetColumnsInfo.REPLYCOUNT_TAG)
												.toString());
						fullMap.put(GetColumnsInfo.PTIME_TAG, map
								.get(GetColumnsInfo.PTIME_TAG) == null ? ""
								: map.get(GetColumnsInfo.PTIME_TAG).toString());
						fullMap.put(GetColumnsInfo.SOURCE_TAG, map
								.get(GetColumnsInfo.SOURCE_TAG) == null ? ""
								: map.get(GetColumnsInfo.SOURCE_TAG).toString());
						fullMap.put(
								GetColumnsInfo.REPLYBOARD_TAG,
								map.get(GetColumnsInfo.REPLYBOARD_TAG) == null ? ""
										: map.get(GetColumnsInfo.REPLYBOARD_TAG)
												.toString());
						fullMap.put(GetColumnsInfo.HASNEXT_TAG, false);
						fullMap.put(GetColumnsInfo.PICNAWS_TAG, map.get(GetColumnsInfo.PICNAWS_TAG) == null ? false
								: map.get(GetColumnsInfo.PICNAWS_TAG));
						fullMap.put(GetColumnsInfo.TEMPLATE_TAG, map.get(GetColumnsInfo.TEMPLATE_TAG) == null ? false
								: map.get(GetColumnsInfo.TEMPLATE_TAG));

						List<Map<String, Object>> imglist = new ArrayList<Map<String, Object>>();
						List<Map<String, Object>> mapImglist = (List<Map<String, Object>>) map.get(GetColumnsInfo.IMG_TAG);
						List<Map<String, Object>> moreImglist = (List<Map<String, Object>>) moreMap.get(GetColumnsInfo.IMG_TAG);
						List<Map<String, Object>> tempmoreImglist = new ArrayList<Map<String, Object>>();
						imglist.addAll((List<Map<String, Object>>) map.get(GetColumnsInfo.IMG_TAG));
						String imgref = "";
						String imgalt = "";
						String imgsrc = "";
						String body = moreMap.get(GetColumnsInfo.BODY_TAG) == null ? ""
								: (String)moreMap.get(GetColumnsInfo.BODY_TAG);
						int mapimgSize = mapImglist.size();
						for (int i = 0; moreImglist != null
								&& i < moreImglist.size(); i++) {
							imgref = moreImglist.get(i).get(GetColumnsInfo.REF_TAG) == null ? ""
									: (String)moreImglist.get(i).get(GetColumnsInfo.REF_TAG);
							imgalt = moreImglist.get(i).get(GetColumnsInfo.ALT_TAG) == null ? ""
									: (String)moreImglist.get(i).get(GetColumnsInfo.ALT_TAG);
							imgsrc = moreImglist.get(i).get(GetColumnsInfo.SRC_TAG) == null ? ""
									: (String)moreImglist.get(i).get(GetColumnsInfo.SRC_TAG);

							if (!imgref.equals(""))
								body = body.replace(imgref, "<!--MORE-IMG#" + (mapimgSize + i) + "-->");

							HashMap<String, Object> tempmap = new HashMap<String, Object>();
							tempmap.put(GetColumnsInfo.REF_TAG, "<!--IMG#"
									+ (mapimgSize + i) + "-->");
							tempmap.put(GetColumnsInfo.ALT_TAG, imgalt);
							tempmap.put(GetColumnsInfo.SRC_TAG, imgsrc);
							tempmoreImglist.add(tempmap);
						}
						/* 做规避处理，否则替换会乱 */
						body = body.replace("<!--MORE-IMG#", "<!--IMG#");
						imglist.addAll(tempmoreImglist);
						fullMap.put(GetColumnsInfo.IMG_TAG, imglist);

						List<Map<String, Object>> linklist = new ArrayList<Map<String, Object>>();
						List<Map<String, Object>> mapLinklist = (List<Map<String, Object>>) map.get(GetColumnsInfo.LINK_TAG);
						linklist.addAll(mapLinklist);
						List<Map<String, Object>> moreLinklist = (List<Map<String, Object>>) moreMap.get(GetColumnsInfo.LINK_TAG);
						List<Map<String, Object>> tempmoreLinklist = new ArrayList<Map<String, Object>>();
						String linkref = "";
						String linktitle = "";
						for (int i = 0; moreLinklist != null
								&& i < moreLinklist.size(); i++) {
							linkref = moreLinklist.get(i).get(GetColumnsInfo.REF_TAG) == null ? ""
									: (String)moreLinklist.get(i).get(GetColumnsInfo.REF_TAG);

							int linkrefend = linkref.indexOf("-->");
							if (linkrefend != -1) {
								linktitle = linkref.substring(linkrefend + 3);
							}
							if (!linkref.equals(""))
								body = body.replace(linkref, "<!--link"
										+ (mapLinklist.size() + i) + "-->" + linktitle);

							HashMap<String, Object> tempmap = new HashMap<String, Object>();

							tempmap.put(GetColumnsInfo.REF_TAG, "<!--link"
									+ (mapLinklist.size() + i) + "-->" + linktitle);
							tempmap.put(GetColumnsInfo.HREF_TAG, moreLinklist
									.get(i).get(GetColumnsInfo.HREF_TAG));
							tempmap.put(GetColumnsInfo.TITLE_TAG, moreLinklist
									.get(i).get(GetColumnsInfo.TITLE_TAG));

							tempmoreLinklist.add(tempmap);
						}
						linklist.addAll(tempmoreLinklist);
						fullMap.put(GetColumnsInfo.LINK_TAG, linklist);

						body = map.get(GetColumnsInfo.BODY_TAG) == null ? ""
								: (String)map.get(GetColumnsInfo.BODY_TAG) + body;
						fullMap.put(GetColumnsInfo.BODY_TAG, body);

						((WebView) ((FrameLayout) mViewFlipper.getCurrentView())
								.getChildAt(0)).loadUrl("javascript:getMore()");

						if (FileUtils.isSDCardMounted()) {
							if (FileUtils.isFileExit(FileUtils.DetailPageTempDir + docid)) {
								File f = new File(FileUtils.DetailPageTempDir + docid);
								f.delete();
							}
							
							FileUtils.writeDetailPageData(fullMap, docid);
						}

					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}

				break;
			case 5:
				hideProgress();
				if (map != null) map.clear();
				
				DetailPageBean bean3 = (DetailPageBean) msg.getData().getSerializable("contents");

				if (bean3 != null && bean3.getData() != null)
					map = bean3.getData();
				
				if (!isCollect && (map == null || map.isEmpty())) {
					if (!Tools.CheckNetwork(mContext)) {
						Toast.makeText(mContext, R.string.msg_net_error, Toast.LENGTH_SHORT).show();
					} else {
						Toast.makeText(mContext, R.string.msg_get_news_error, Toast.LENGTH_SHORT).show();
					}
					mLoaddingView.setVisibility(View.GONE);
					((FrameLayout) mViewFlipper.getCurrentView()).getChildAt(1).setVisibility(View.GONE);
					mLoaddingErrorView.setVisibility(View.VISIBLE);
				} else {
					mLoaddingErrorView.setVisibility(View.GONE);
					
					if (map.get(GetColumnsInfo.REPLYCOUNT_TAG) != null
							&& ! "".equals(String.valueOf(map.get(GetColumnsInfo.REPLYCOUNT_TAG)))) {
						int c1 = 0;
						int c2 = 0;
						try {
							c1 = Integer.parseInt(map.get( GetColumnsInfo.REPLYCOUNT_TAG).toString());
							if (null == replyCountNum || "".equals(replyCountNum)) {
								replyCountNum = "0";
							}
							c2 = Integer.parseInt(replyCountNum);
						} catch (NumberFormatException e) {
							e.printStackTrace();
						}
						replyCountNum = Math.max(c1, c2) + "";
					}

					if (replyCountNum != null && !replyCountNum.equals("")) {
						mCommentBtn.setText(replyCountNum + "跟贴");
					}
					WebView webView = (WebView)((FrameLayout)mViewFlipper.getCurrentView()).getChildAt(0);
					webView.setVisibility(View.VISIBLE);
					webView.loadUrl(mHtmlPath);
					
					setIsReaded4List(docid);
					FileUtils.writeDetailPageData(map, docid);
				}
				setCollectStatus();
				break;
			case 8:
				if (reply_edittext_layout.getVisibility() == View.VISIBLE) {
					reply_img_layout.setVisibility(View.VISIBLE);
					reply_edittext_layout.setVisibility(View.GONE);
					if (mInputMethodManager != null) {
						mInputMethodManager.hideSoftInputFromWindow(replyEditText.getWindowToken(), 0);
					}
					if (mTopBanner.getVisibility() == View.GONE) {
						mTopBanner.startAnimation(slideTopIn);
					}
					break;
				}

				if (mTopBanner.getVisibility() == View.VISIBLE
						&& replyLayout.getVisibility() == View.VISIBLE) {
					if ((slideTopOut.hasStarted() && !slideTopOut.hasEnded())
							|| (slideBottomOut.hasStarted() && !slideBottomOut
									.hasEnded())) {
						mTopBanner.clearAnimation();
						replyLayout.clearAnimation();
						mTopBanner.setVisibility(View.VISIBLE);
						replyLayout.setVisibility(View.VISIBLE);

						slideTopOut = AnimationUtils.loadAnimation(mContext, R.anim.slide_top_out);
						slideBottomOut = AnimationUtils.loadAnimation(mContext, R.anim.slide_bottom_out);
					} else {
						mTopBanner.startAnimation(slideTopOut);
						replyLayout.startAnimation(slideBottomOut);
					}

				} else if (mTopBanner.getVisibility() == View.GONE
						&& replyLayout.getVisibility() == View.GONE) {
					if ((slideTopIn.hasStarted() && !slideTopIn.hasEnded())
							|| (slideBottomIn.hasStarted() && !slideBottomIn
									.hasEnded())) {
						mTopBanner.clearAnimation();
						replyLayout.clearAnimation();
						mTopBanner.setVisibility(View.GONE);
						replyLayout.setVisibility(View.GONE);

						slideTopIn = AnimationUtils.loadAnimation(mContext, R.anim.slide_top_in);
						slideBottomIn = AnimationUtils.loadAnimation(mContext, R.anim.slide_bottom_in);
					} else {
						mTopBanner.startAnimation(slideTopIn);
						replyLayout.startAnimation(slideBottomIn);
					}

				}
				setAnimations();
				break;
			case 15:
				if (mPostCommentDialog != null && mPostCommentDialog.isShowing())
					mPostCommentDialog.dismiss();
				if (msg.obj != null) {
					if (msg.obj.toString().equals("1")) {
						Toast.makeText(mContext, R.string.post_success, Toast.LENGTH_SHORT).show();
						replyEditText.setText("");
					}  else {
						Toast.makeText(mContext, R.string.post_fail, Toast.LENGTH_SHORT).show();
					}

					if (mInputMethodManager != null) {
						mInputMethodManager.hideSoftInputFromWindow(replyEditText.getWindowToken(), 0);
					}
					mTopBanner.setVisibility(View.VISIBLE);
					reply_img_layout.setVisibility(View.VISIBLE);
					reply_edittext_layout.setVisibility(View.GONE);

				} else {
					Toast.makeText(mContext, R.string.post_fail, Toast.LENGTH_SHORT).show();
				}

				break;
			case 16:
				if (reply_edittext_layout.getVisibility() == View.VISIBLE) {
					reply_img_layout.setVisibility(View.VISIBLE);
					reply_edittext_layout.setVisibility(View.GONE);
					if (mInputMethodManager != null) {
						mInputMethodManager.hideSoftInputFromWindow(replyEditText.getWindowToken(), 0);
					}
					if (mTopBanner.getVisibility() == View.GONE) {
						mTopBanner.startAnimation(slideTopIn);
					}
				}
				break;
			case 100:
				((WebView) ((FrameLayout) mViewFlipper.getCurrentView())
						.getChildAt(0)).loadUrl(mHtmlPath);
				if (map.get(GetColumnsInfo.REPLYCOUNT_TAG) != null) {
					int c1 = 0;
					int c2 = 0;
					try {
						c1 = Integer.parseInt(String.valueOf(map.get(GetColumnsInfo.REPLYCOUNT_TAG)));
						c2 = Integer.parseInt(replyCountNum);
					} catch (NumberFormatException e) {
					}
					replyCountNum = Math.max(c1, c2) + "";
				}

				if (replyCountNum != null && !replyCountNum.equals("")) {
					mCommentBtn.setText(replyCountNum + "跟贴");
				}
				break;
			case 101:
				boolean enable = (Boolean) msg.obj;
				enableReply(enable);
				break;
			case 404:// 获取网络文章异常
				Toast.makeText(mContext, R.string.msg_net_error, Toast.LENGTH_SHORT).show();
				mNewsContentView.setVisibility(View.GONE);
				mLoaddingErrorView.setVisibility(View.VISIBLE);
				break;
			}
		}
	};
	
	@Override
    public boolean hasTitleBar() {
        return true;
    }

    public void onApplyTheme() {
		super.onApplyTheme();
		Context context = getActivity();
		ThemeSettingsHelper themeSettingsHelper = getThemeSettingsHelper();
		View view = getView();
		
		View titleView = getTitleView();
		if (titleView != null) {
		    CommonFrameActivity.applyThemeForDefaultTitleView(context, themeSettingsHelper, titleView);
		}
		
		themeSettingsHelper.setViewBackgroudColor(context, view.findViewById(R.id.container),R.color.main_bg_color);
		
        if (mCommentBtn != null) {
            themeSettingsHelper.setViewBackgroud(context, mCommentBtn, R.drawable.topcomment_column);
            themeSettingsHelper.setTextViewColor(context, mCommentBtn, R.color.top_image_title_color);
            
            if(ThemeSettingsHelper.THEME_OLYMPIC.equals(themeSettingsHelper.getCurrentThemePackage(mContext))){
            	mCommentBtn.setPadding(10, 2, 10, 2);
            }
        }
		
        themeSettingsHelper.setImageViewSrc(context, (ImageView)view.findViewById(R.id.reply_img_button), R.drawable.reply_editbox_bk);
        themeSettingsHelper.setViewBackgroud(context, replyLayout, R.drawable.reply_frame_bk);
        themeSettingsHelper.setViewBackgroud(context, collectBtn, R.drawable.collect_button_selector);
        themeSettingsHelper.setImageViewSrc(context, (ImageView) replyLayout.findViewById(R.id.reply_frame_divider_img0), R.drawable.reply_frame_divider);
        themeSettingsHelper.setImageViewSrc(context, (ImageView) replyLayout.findViewById(R.id.reply_frame_divider_img1), R.drawable.reply_frame_divider);
        themeSettingsHelper.setImageViewSrc(context, (ImageView) replyLayout.findViewById(R.id.reply_frame_divider_img2), R.drawable.reply_frame_divider);

        themeSettingsHelper.setImageViewSrc(context, share_button, R.drawable.share_button_selector);
        themeSettingsHelper.setViewBackgroud(context, replyButton,
				R.drawable.netease_big_button);
        themeSettingsHelper.setTextViewColor(context, replyButton,
				R.color.list_title_color);

        themeSettingsHelper.setViewBackgroudColor(context, mLoaddingView, R.color.main_bg_color);
        themeSettingsHelper.setViewBackgroudColor(context, mLoaddingErrorView, R.color.main_bg_color);
        themeSettingsHelper.setViewBackgroudColor(context, mWebView1, R.color.main_bg_color);
        themeSettingsHelper.setViewBackgroudColor(context, mWebView2, R.color.main_bg_color);


		// 菜单夜间模式
        View menuView = getMenuView();
        themeSettingsHelper.setViewBackgroudColor(mContext, menuView.findViewById(R.id.menu_tabrow_1), R.color.menu_layout_bg_color);
        themeSettingsHelper.setViewBackgroudColor(mContext, menuView.findViewById(R.id.menu_tabrow_2), R.color.menu_layout_bg_color);
        
		LinearLayout menuItem = (LinearLayout) menuView.findViewById(R.id.menu_refresh);
        applyThemeForMenu(mContext, themeSettingsHelper, menuItem, true);
        menuItem = (LinearLayout) menuView.findViewById(R.id.menu_selecttext);
        applyThemeForMenu(mContext, themeSettingsHelper, menuItem, true);
        menuItem = (LinearLayout) menuView.findViewById(R.id.menu_textsize);
        applyThemeForMenu(mContext, themeSettingsHelper, menuItem, false);
        menuItem = (LinearLayout) menuView.findViewById(R.id.menu_my_comment);
        applyThemeForMenu(mContext, themeSettingsHelper, menuItem, false);
        menuItem = (LinearLayout) menuView.findViewById(R.id.menu_my_collect);
        applyThemeForMenu(mContext, themeSettingsHelper, menuItem, false);
	}
	
	private void applyThemeForMenu(Context context, ThemeSettingsHelper themeSettingsHelper,
            LinearLayout menuView, boolean isUp) {
        themeSettingsHelper.setViewBackgroud(context, menuView, isUp ? R.drawable.menu_background
                : R.drawable.menu_background_below);
        themeSettingsHelper.setTextViewColor(context, (TextView) menuView.getChildAt(1),
                R.color.menu_text_color);

    }
	
}
